/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package gdatastructure;

import java.util.Random;

/**
 *
 * @author ASUS
 */
public class Steat { //街道类
    public int index;//在图函数中streat的下标
    private double a;//该街道上所带有的函数ax+by+c=0的a
    private double b;
    private double c;
    public int from;  //街道的初始点的下标
    public int to;  //街道的末尾点的下标
    private double domain1; //函数方程的定义域  起点横坐标
    private double domain2;//终点横坐标
    int havecar; //代表这条街道上没有车
    public double length;//距离
    public newpoint[] point;
    public car[] n;
    
    Steat(int x){
        index=0;
        a=0;
        b=0;
        c=0;
        from=0;
        to=0;
        domain1=0;
        domain2=0;
        length=0;
        havecar=0;
        n = new car[3]; //这里已经默认了一条街道上最多有3辆车，需要可以再之后改
        for(int k=0;k<=2;k++)
		n[k] = new car();
    }
    
    public void delectcar(int j){ //删除街道上的一辆车
        int i,k=-1;
        for(i=j;i<havecar;i++){
            if(i<=1){
                n[i]=n[i+1];
            }
            n[havecar-1].setTurnfrom(k);
        }
    }
    
    public void createcar(){ //创立车结点
        
        int i;//街道上车的数量
        Random r=new Random(20);
        Random rand = new Random();
        int la=(int)domain1;
        int lb=(int)domain2;
        i=r.nextInt(2);//街道上随机生成0~1辆车
        car it =new car(0,0,0,0,0);
        for(int k=0;k<=2;k++)
        {
            n[k] = new car();
            n[k].number=k; //将街道上的车辆的数位放入车辆类
        }
        this.havecar=i; 
        for(int j=0;j<=i;j++){ //车辆数组，是从0开始的，到2结束
            double carx=0,cary;
            if(domain1<domain2) //随机生成车辆的x与y值
                carx=domain1+rand.nextDouble()+rand.nextInt(lb-la);
            if(domain1>domain2)
                carx=domain2+rand.nextDouble()+rand.nextInt(la-lb);
            cary=(a*carx+c)*(-1)/b;
            n[j].setX(carx);
            n[j].setY(cary);
            n[j].setStreat(index);
            double tempx1,tempy1,tempx2,tempy2;
            tempx1=domain1;
            tempy1=(a*tempx1+c)*(-1)/b;
            tempx2=domain2;
            tempy2=(a*tempx2+c)*(-1)/b;
            double len1,len2;//将距离起点和末尾点之间的距离求出来，存放进去
            len1=Math.sqrt((carx-tempx1)*(carx-tempx1)+(cary-tempy1)*(cary-tempy1));
            len2=Math.sqrt((carx-tempx2)*(carx-tempx2)+(cary-tempy2)*(cary-tempy2));
            n[j].setTurnfrom(len1);
            n[j].setTurnto(len2);
        }
    }
    public void setfrom(int a){
        this.from=a;
    }
    
    public void setto(int a){
        this.to=a;
    }
    
    public void setlength(double x){
        this.length=x;
    }
    public void setFrom(int a){
        this.from=a;
    }
    public void setTo(int a){
        this.to=a;
    }

    public double getDomain1() {
        return domain1;
    }

    public void setDomain1(double domain1) {
        this.domain1 = domain1;
    }

    public double getDomain2() {
        return domain2;
    }

    public void setDomain2(double domain2) {
        this.domain2 = domain2;
    }
    
    
    public void setA(double x){
        this.a=x;
    }
    public double getA(){
        double x;
        x=this.a;
        return x;
    }
    public void setB(double x){
        this.b=x;
    }
    public double getB(){
        double x;
        x=this.b;
        return x;
    }
    public void setC(double x){
        this.c=x;
    }
    public double getC(){
        double x;
        x=this.c;
        return x;
    }
}
